// 题目: 进制转换(10-16).png
#include <stdio.h>
#include <stdlib.h>

typedef int DataType;
struct SeqStackNode
{
    int MAX;
    int top;
    DataType *elem;
};
typedef struct SeqStackNode *SeqStack;

SeqStack SetNullStack_Seq(int m)
{
    SeqStack sstack = (SeqStack)malloc(sizeof(struct SeqStackNode));
    if (sstack != NULL)
    {
        sstack->elem = (int *)malloc(sizeof(int) * m);
        if (sstack->elem != NULL)
        {
            sstack->MAX = m;
            sstack->top = -1;
            return (sstack);
        }
        else
        {
            free(sstack);
            return NULL;
        }
    }
    else
    {
        printf("out of space");
        return NULL;
    }
}

int IsNullStack_seq(SeqStack sstack)
{
    return (sstack->top == -1);
}
void Push_seq(SeqStack sstack, int x) // 入栈函数
{
    sstack->elem[++sstack->top] = x;
}
void Pop_seq(SeqStack sstack)
{
    if (IsNullStack_seq(sstack))
        printf("Underflow!\n");
    else
        sstack->top = sstack->top - 1;
}
DataType Top_seq(SeqStack sstack)
{
    if (IsNullStack_seq(sstack))
    {
        printf("it is empty");
        return 0;
    }
    else
        return sstack->elem[sstack->top];
}
void Hexconversion(SeqStack sstack, int n) // 进制转换函数
{
    DataType temp = 0;
    while (n >= 1)
    {
        if (sstack->top == sstack->MAX - 1)
        {
            printf("overflow!\n");
            break;
        }
        Push_seq(sstack, n % 16);
        n = n / 16;
    }
    while (sstack->top > -1)
    {
        temp = Top_seq(sstack);
        Pop_seq(sstack);
        switch (temp)
        {
        case 10:
            printf("A");
            break;
        case 11:
            printf("B");
            break;
        case 12:
            printf("C");
            break;
        case 13:
            printf("D");
            break;
        case 14:
            printf("E");
            break;
        case 15:
            printf("F");
            break;
        default:
            printf("%d", temp);
            break;
        }
    }
}

int main()
{
    SeqStack mystack = NULL;
    int n;
    mystack = SetNullStack_Seq(4);
    scanf("%d", &n);
    Hexconversion(mystack, n);
    return 0;
}